package com.ruoyi.web.controller.community.complain;

import java.util.Date;
import java.util.List;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.community.service.IComplainService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.community.domain.Complain;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 业主投诉Controller
 * 
 * @author 袁现程
 * @date 2021-08-07
 */
@RestController
@RequestMapping("/community/complain")
public class ComplainController extends BaseController
{
    @Autowired
    private IComplainService complainService;

    /**
     * 按社区查询业主投诉列表
     */
    @GetMapping("/list")
    public TableDataInfo list(Complain complain)
    {
        startPage();
        List<Complain> list = complainService.selectComplainList(complain);
        return getDataTable(list);
    }

    /**
     * 导出业主投诉列表
     */
    @Log(title = "业主投诉", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Complain complain)
    {
        List<Complain> list = complainService.selectComplainList(complain);
        ExcelUtil<Complain> util = new ExcelUtil<Complain>(Complain.class);
        return util.exportExcel(list, "业主投诉数据");
    }

    /**
     * 获取业主投诉详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(complainService.selectComplainById(id));
    }

    /**
     * 修改业主投诉
     */
    @Log(title = "业主投诉", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Complain complain)
    {
        return toAjax(complainService.updateComplain(complain));
    }

    /**
     * 删除业主投诉
     */
    @Log(title = "业主投诉", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(complainService.deleteComplainByIds(ids));
    }

    /**
     * 小程序新增业主投诉
     */
    @Log(title = "业主投诉", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Complain complain)
    {
        return toAjax(complainService.insertComplain(complain));
    }

    /**
     * 小程序业主查询自己的投诉信息,包括正在处理中的和处理完成的
     */
    @GetMapping("/")
    public AjaxResult listByUserId() {
        return AjaxResult.success(complainService.selectListByUserId());
    }
}
